package com.sd.repay.transfer;

import com.sd.repay.common.CommonResult;
import com.sd.repay.pojo.TransferOrder;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * 代付订单校工具类
 *
 * @author sd
 */
@Service
public class TransferCheckUtils {


    /**
     * 出款订单基础校验
     *
     * @param transferOrder 订单信息
     * @return
     */
    public CommonResult basicsTransferOrderCheck(TransferOrder transferOrder) {
        CommonResult result = new CommonResult();

        if (StringUtils.isBlank(transferOrder.getOrderType())) {
            result.setStatus(2);
            result.setMsg("订单类型不允许为空");
            return result;
        }


        if (StringUtils.isBlank(transferOrder.getSourceOrderNo())) {
            result.setStatus(2);
            result.setMsg("来源订单号不允许为空");
            return result;
        }


        if (StringUtils.isBlank(transferOrder.getTradeSource())) {
            result.setStatus(2);
            result.setMsg("交易来源不允许为空");
            return result;
        }


        if (StringUtils.isBlank(transferOrder.getMerType())) {
            result.setStatus(2);
            result.setMsg("商户类型不允许为空");
            return result;
        }


        if (StringUtils.isBlank(transferOrder.getMerNo())) {
            result.setStatus(2);
            result.setMsg("商户号不允许为空");
            return result;
        }


        if (StringUtils.isBlank(transferOrder.getInAccNo()) && StringUtils.isBlank(transferOrder.getInToken())) {
            result.setStatus(2);
            result.setMsg("入账卡号与入账token必须有一种不为空");
            return result;
        }


        if (StringUtils.isBlank(transferOrder.getInAccName())) {
            result.setStatus(2);
            result.setMsg("入账姓名不允许为空");
            return result;
        }


        if (StringUtils.isBlank(transferOrder.getInBankName())) {
            result.setStatus(2);
            result.setMsg("入账银行名不允许为空");
            return result;
        }


        if (StringUtils.isBlank(transferOrder.getMobileNo())) {
            result.setStatus(2);
            result.setMsg("手机号不允许为空");
            return result;
        }


        if (StringUtils.isBlank(transferOrder.getIdentityType())) {
            result.setStatus(2);
            result.setMsg("证件类型不允许为空");
            return result;
        }


        if (StringUtils.isBlank(transferOrder.getIdentityNo())) {
            result.setStatus(2);
            result.setMsg("证件号不允许为空");
            return result;
        }


        if (transferOrder.getAmount() == null || transferOrder.getAmount().compareTo(new BigDecimal("0")) < 1) {
            result.setStatus(2);
            result.setMsg("金额必须大于 0");
            return result;
        }

        result.setStatus(1);
        return result;
    }
}
